package handle

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"yk1/api/basic/config"
	__ "yk1/api/basic/proto"
	"yk1/api/request"
)

func RiderAdd(c *gin.Context) {
	var req request.RiderAddReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "参数验证失败",
			"data": err.Error(),
		})
		return
	}
	r, err := config.Client.RiderAdd(c, &__.RiderAddReq{
		UserId:    int64(req.UserId),
		Name:      req.Name,
		Mobile:    req.Mobile,
		IdCard:    req.IdCard,
		BikeNo:    req.BikeNo,
		StationId: req.StationId,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "骑手注册失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 400,
		"msg":  "参数验证失败",
		"data": r,
	})
	return

}

func Message(c *gin.Context) {
	var req request.MessageAddReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "参数验证失败",
			"data": err.Error(),
		})
		return
	}
	r, err := config.Client.MessageAdd(c, &__.MessageAddReq{
		UserId:  int64(req.UserId),
		Mobile:  req.Mobile,
		Message: req.Message,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "消息发送失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "消息发送成功",
		"data": r,
	})
}
